import { routing } from "../../utils/routing";

// pages/lock/lock.ts
Page({
  data: {
    avatarURL: "",
  },
  async onLoad(opt: Record<"car_id", string>) {
    const o: routing.LockOpts = opt;
    console.log("unlocking car", o.car_id);
  },
  onGetUserInfo() {},
  onUnlockTap() {
    wx.getLocation({
      type: "gcj02",
      success: (loc) => {
        console.log("starting a trip", {
          location: {
            latitude: loc.latitude,
            longitude: loc.longitude,
          },
        });
        const tripID = "trip666";
        wx.showLoading({ title: "开锁中", mask: true });
        setTimeout(() => {
          wx.redirectTo({
            // url: `/pages/driving/driving?tripID=${tripID}`,
            url: routing.drving({
              trip_id: tripID,
            }),
            complete: () => {
              wx.hideLoading();
            },
          });
        }, 2000);
      },
      fail: () => {
        wx.showToast({
          icon: "none",
          title: "前往设置获取位置权限",
        });
      },
    });
  },
});
